package edu.codink.common.base;

import java.io.Serializable;

/**
 * 分页对象
 * @author blue
 *
 */
public class Page implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6864154192264700085L;

	/**
	 * 每页记录数
	 */
	private long pageSize = 20;

	/**
	 * 当前页数
	 */
	private long currentPage;
	/**
	 * 页数
	 */
	private long pageCount;
	/**
	 * 记录数
	 */
	private long recordCount;
	
	/**
	 * 从第几条开始查询
	 */
	private int start;
	/**
	 * 查询条数
	 */
	private int limit;

	public int getCurrentPage() {
		if (currentPage < 1)
			currentPage = 1;
		if (currentPage > pageCount)
			currentPage = pageCount;
		return Long.valueOf(currentPage).intValue();
	}

	/**
	 * 
	 * @return
	 */
	public int getStartRow() {
		Long startRow = pageSize * (getCurrentPage() - 1);
		if (startRow < 1) {
			return 0;
		}
		return startRow.intValue();
	}

	/**
	 * 
	 * @param totaItemNum
	 * @param pageItemCount
	 * @return
	 */
	public long getPageCount(long totaItemNum, long pageItemCount) {
		long totalPageNum = totaItemNum / pageItemCount;
		if (totaItemNum % pageItemCount != 0) {
			totalPageNum++;
		}
		return totalPageNum;
	}
	/**
	 * 
	 * @param recordCount
	 */
	public void setRecordCount(long recordCount) {
		this.recordCount = recordCount;
		if (pageSize > 0) {
			setPageCount(getPageCount(recordCount, pageSize));
		}
	}
	
	public void setCurrentPage(long currentPage) {
		this.currentPage = currentPage;
	}

	public long getPageCount() {
		return pageCount;
	}

	public void setPageCount(long pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageSize() {
		return Long.valueOf(pageSize).intValue();
	}

	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}

	public long getRecordCount() {
		return recordCount;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}
}
